<template>
	<view class="temListMsg">
		<uni-section title="队长：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.originators}}</text>
			</view>
		</uni-section>
		<uni-section title="队伍名字：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.teamName}}</text>
			</view>
		</uni-section>
		<uni-section title="类型：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.type == 1 ? '个人' : '组织'}}</text>
			</view>
		</uni-section>
		<uni-section title="队伍总人数：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.teamNum}}</text>
			</view>
		</uni-section>
		<uni-section title="队伍加入人数：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.member.length}}</text>
			</view>
		</uni-section>
		<uni-section title="队伍情况：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.situation}}</text>
			</view>
		</uni-section>
		<uni-section title="队伍目标：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.goal}}</text>
			</view>
		</uni-section>
		<uni-section title="招收对象：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.recruit}}</text>
			</view>
		</uni-section>
		<uni-section title="对投稿者的要求：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.recruitNeed}}</text>
			</view>
		</uni-section>
		<uni-section title="队伍标签：" type="line">
			<view class="example-name f16">
				<view class="tag">
					<template v-for="item  in  currentItem.tags ">
						<tag :key="item" :name="item" />

					</template>
				</view>
			</view>
		</uni-section>

		<uni-section title="对应项目名称：" type="line">
			<view class="example-name f16">
				<text class="number">{{currentItem.teamProjectName }}</text>
			</view>
		</uni-section>

		<view class="button">
			<view type="primary" class="button_item f14 margin-right16" @click="dialogToggle">加入</view>
			<view type="primary" class="button_item f14" @click="zixun">和他聊聊</view>
		</view>
		<uni-popup ref="alertDialog" type="dialog">
			<uni-popup-dialog :type="msgType" cancelText="算了" confirmText="确定" title="温馨提示"
				content="确定要申请队伍吗, 队长可查看你的简历信息" @confirm="dialogConfirm" @close="dialogClose"></uni-popup-dialog>
		</uni-popup>
	</view>
</template>

<script>
	import tag from '@/components/tag/index.vue'
	export default {
		data() {
			return {
				currentItem: null,
				type: 'center',
				msgType: 'success',
				formData: {
					fromStr: "组队系统发送",
					msg: "",
					toId: 0,
					toStr: "",
					type: "Team"
				}
			}
		},
		components: {
			tag
		},
		methods: {
			reset() {
				this.formData = {
					fromStr: "组队系统发送",
					msg: "",
					toId: 0,
					toStr: "",
					type: "Team"
				}
			},
			async dialogToggle() {
				if (!this.$userInfo || this.$userInfo == undefined || this.$userInfo == '' || this
					.$userInfo == null) {
					try {
						const res = await this.$mjcrequest.request({
							url: this.$api.getUser,
							method: 'GET',
							header: this.$aplsjsonheader,
						})
						this.$binduserInfo(res)
						console.log(this.$userInfo, 269);
					} catch (e) {

						this.$errMessageToast(e)
					}
				}

				const id = this.$userInfo.id
				if (this.currentItem.captionId == id) {
					this.$errMessageToast('你是队长无法发起加入')
					return
				}
				this.$refs.alertDialog.open()
			},
			async dialogConfirm() {
				console.log('点击确认')
				uni.showLoading({
					title: '加载中'
				});
				try {
					const data = {
						teamId: String(this.currentItem.teamId)
					}
					const result = await this.$mjcrequest.request({
						url: this.$api.apply2JoinTeam,
						data: JSON.stringify(data),
						header: this.$aplsjsonheader,
						isNotLoading: true
					});
					const getresumeresult = await this.$mjcrequest.request({
						url: this.$api.getresume,
						method: 'GET',
						header: this.$aplsjsonheader,
						isNotLoading: true
					})
					const resumeMsg = {
						...getresumeresult.wyuMsg,
						...getresumeresult.resumeMsg,
						teamId: this.currentItem.teamId
					}
					console.log(resumeMsg);
					//推送加入消息给队长
					const pushData = {
						...this.formData,
						msg: JSON.stringify(resumeMsg),
						fromStr: resumeMsg.userName + '给你的队伍发送了一条简历加入',
						toStr: '发送给' + this.currentItem.teamName + '的队长',
						toId: String(this.currentItem.captionId),
						type: 'reSume'
					}
					const res = await this.$mjcrequest.request({
						url: this.$api.Send,
						data: JSON.stringify(pushData),
						isToast: true,
						header: this.$aplsjsonheader,
						isNotLoading: true
					})
					uni.hideLoading();

					console.log(res);
					//消息推送
				} catch (e) {
					this.$errMessageToast(e)
					//TODO handle the exception
				}
			},
			dialogClose() {
				console.log('点击关闭')
				this.reset()
			},

			async zixun() {
				if (!this.$varitfyToken()) {
					this.$errMessageToast('请绑定五邑大学账号')
					return
				}
				if (!this.$userInfo || this.$userInfo == undefined || this.$userInfo == '' || this
					.$userInfo == null) {
					try {
						const res = await this.$mjcrequest.request({
							url: this.$api.getUser,
							method: 'GET',
							header: this.$aplsjsonheader,
						})
						this.$binduserInfo(res)
						console.log(this.$userInfo, 269);
					} catch (e) {

						this.$errMessageToast(e)
					}
				}

				const id = this.$userInfo.id
				if (this.currentItem.captionId == id) {
					this.$errMessageToast('无法与自己对话聊天')
					return
				}
				uni.navigateTo({
					url: '/pages/commutation/commutation?captionId=' + this.currentItem.captionId +
						"&originators=" + encodeURIComponent(this.currentItem.originators) +
						'&teamId=' + this.currentItem.teamId

				})
				// this.inputDialogToggle()
			}
		},

		created() {
			this.$eventBus.$on('temListMsgSend', (res) => {
				console.log(res, 20);
				this.currentItem = res
			})
			this.$eventBus.$emit('temListMsg')
		},
		destroyed() {
			this.$eventBus.$off('temListMsgSend')
		}
	}
</script>

<style lang="less" scoped>
	.temListMsg {
		padding: 0 15rpx;
		padding-bottom: 20rpx;
		height: 100vh;
		width: 100%;
		background-color: #fff;
		box-sizing: border-box;
		overflow-x: hidden;
		padding: 30rpx 20rpx 55rpx 20rpx;

		.example-name {
			padding: 5px 10px;
		}

		.button {
			display: flex;
			margin-top: 15rpx;
			justify-content: center;
			margin-top: 20px;

			&_item {
				width: auto;
				background-color: #2ebef3;
				color: #fff;
				padding: 15rpx 35rpx;
				border-radius: 15rpx;
			}
		}



		.box {
			margin: 25rpx 0;
		}

		.erjiTitle {
			font-weight: 700;
			font-size: 40rpx;
		}

		.title {
			font-size: 60rpx;
			font-weight: 700;
			text-align: center;
		}

		.time {
			font-size: 35rpx;
			margin: 15rpx 0;

		}

	}
</style>
